home *** CD-ROM | disk | FTP | other *** search
/ Inside Multimedia 1994 April / Inside Multimedia CD-ROM (April 1994).iso / prg / gs / gssource.exe / ICCFONT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-24  |  6.5 KB  |  217 lines

  1. /* Copyright (C) 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* iccfont.c */
  21. /* Initialization support for compiled fonts */
  22. #include "string_.h"
  23. #include "ghost.h"
  24. #include "alloc.h"
  25. #include "ccfont.h"
  26. #include "dict.h"
  27. #include "dstack.h"
  28. #include "errors.h"
  29. #include "iutil.h"
  30. #include "name.h"
  31. #include "oper.h"
  32. #include "save.h"            /* for alloc_refs */
  33. #include "store.h"
  34.  
  35. extern ref name_StandardEncoding;
  36.  
  37. /* Forward references */
  38. private int cfont_ref_dict_create(P3(ref *, const cfont_dict_keys _ds *,
  39.                      const ref _ds * _ds *));
  40. private int cfont_string_dict_create(P3(ref *, const cfont_dict_keys _ds *,
  41.                     const const_charray _ds *));
  42. private int cfont_num_dict_create(P3(ref *, const cfont_dict_keys _ds *,
  43.                      const float _ds *));
  44. private int cfont_name_array_create(P3(ref *, const char _ds * _ds *, int));
  45. private int cfont_dict_put(P3(ref *, const char _ds *, const ref *));
  46.  
  47. /* Procedure vector passed to font initialization procedures. */
  48. private const cfont_procs ccfont_procs = {
  49.     cfont_ref_dict_create,
  50.     cfont_string_dict_create,
  51.     cfont_num_dict_create,
  52.     cfont_name_array_create,
  53.     cfont_dict_put
  54. };
  55.  
  56. /* ------ Initialization tables ------ */
  57. /* See gconfig.c for documentation on how this works. */
  58. #define device_(dev)
  59. #define oper_(defs)
  60. #define psfile_(fns)
  61.  
  62. /* Generate an operator procedure for each font. */
  63. #define font_(fname, fproc, zfproc)\
  64. extern int fproc(P2(const cfont_procs _ds *, ref *));\
  65. private int zfproc(os_ptr op)\
  66. {    int code = fproc(&ccfont_procs, (ref *)(op + 1));\
  67.     if ( code < 0 ) return code;\
  68.     push(1);\
  69.     return 0;\
  70. }
  71. #include "gconfig.h"
  72.  
  73. /* Generate the operator initialization table. */
  74. #undef font_
  75. #define font_(fname, fproc, zfproc)\
  76.     {fname, zfproc},
  77. op_def ccfonts_op_defs[] = {
  78. #include "gconfig.h"
  79.     op_def_end(0)
  80. };
  81.  
  82. /* ------ Procedural code ------ */
  83.  
  84. /* Check for reaching the end of the keys. */
  85. #define more_keys(kp) ((kp)->num_enc_keys | (kp)->num_str_keys)
  86.  
  87. /* Put the next entry into a dictionary. */
  88. /* We know that more_keys(kp) is true. */
  89. private int
  90. cfont_put_next(ref *pdict, cfont_dict_keys _ss *kp, const ref *pvalue,
  91.   ref * _ss *pencodings)
  92. {    ref kname;
  93.     int code;
  94.     if ( *pencodings == 0 )
  95.        {    /* Create the dictionary and look up the encodings. */
  96.         code = dict_create(kp->num_enc_keys + kp->num_str_keys + kp->extra_slots, pdict);
  97.         if ( code < 0 ) return code;
  98.         make_tasv(&kname, t_string, 0, 17, bytes,
  99.               (byte *)"ISOLatin1Encoding");
  100.         if ( dict_find(&systemdict, &name_StandardEncoding, &pencodings[0]) <= 0 ||
  101.              dict_find(&systemdict, &kname, &pencodings[1]) <= 0
  102.            )
  103.             return e_undefined;
  104.        }
  105.     if ( kp->num_enc_keys )
  106.        {    const charindex _ds *skp = kp->enc_keys++;
  107.         code = array_get(pencodings[skp->encx], (long)(skp->charx), &kname);
  108.         kp->num_enc_keys--;
  109.        }
  110.     else        /* must have kp->num_str_keys != 0 */
  111.        {    const char *skp = *(kp->str_keys++);
  112.         code = name_ref((const byte *)skp, strlen(skp), &kname, 0);
  113.         kp->num_str_keys--;
  114.        }
  115.     return dict_put(pdict, &kname, pvalue);
  116. }
  117.  
  118. /* ------ Routines called from compiled font initialization ------ */
  119.  
  120. /* Create a dictionary with general ref values. */
  121. private int
  122. cfont_ref_dict_create(ref *pdict, const cfont_dict_keys _ds *kp,
  123.   const ref _ds * _ds *values)
  124. {    cfont_dict_keys keys;
  125.     const ref _ds * _ds *vp = values;
  126.     ref *pencodings[2];
  127.     keys = *kp;
  128.     pencodings[0] = 0;
  129.     while ( more_keys(&keys) )
  130.        {    const ref *pvalue = *vp++;
  131.         ref nref;
  132.         int code;
  133.         if ( r_has_type(pvalue, t_name) )
  134.            {    /* The "name" is really a string. */
  135.             /* Convert it to a real name now. */
  136.             code = name_ref(pvalue->value.bytes, r_size(pvalue),
  137.                     &nref, 0);
  138.             if ( code < 0 ) return code;
  139.             pvalue = &nref;
  140.            }
  141.         code = cfont_put_next(pdict, &keys, pvalue, pencodings);
  142.         if ( code < 0 ) return code;
  143.        }
  144.     return 0;
  145. }
  146.  
  147. /* Create a dictionary with string values. */
  148. private int
  149. cfont_string_dict_create(ref *pdict, const cfont_dict_keys _ds *kp,
  150.   const const_charray _ds *values)
  151. {    cfont_dict_keys keys;
  152.     const const_charray _ds *vp = values;
  153.     uint attrs = kp->value_attrs;
  154.     ref *pencodings[2];
  155.     ref vstring;
  156.     keys = *kp;
  157.     pencodings[0] = 0;
  158.     while ( more_keys(&keys) )
  159.        {    int code;
  160.         make_tasv(&vstring, t_string, attrs,
  161.               vp->len, bytes, (byte *)vp->str);
  162.         vp++;
  163.         code = cfont_put_next(pdict, &keys, &vstring, pencodings);
  164.         if ( code < 0 ) return code;
  165.        }
  166.     return 0;
  167. }
  168.  
  169. /* Create a dictionary with number values. */
  170. private int
  171. cfont_num_dict_create(ref *pdict, const cfont_dict_keys _ds *kp,
  172.   const float _ds *values)
  173. {    cfont_dict_keys keys;
  174.     const float _ds *vp = values;
  175.     ref *pencodings[2];
  176.     ref vnum;
  177.     keys = *kp;
  178.     pencodings[0] = 0;
  179.     while ( more_keys(&keys) )
  180.        {    float val = *vp++;
  181.         int code;
  182.         if ( val == (int)val )
  183.             make_int(&vnum, (int)val);
  184.         else
  185.             make_real(&vnum, val);
  186.         code = cfont_put_next(pdict, &keys, &vnum, pencodings);
  187.         if ( code < 0 ) return code;
  188.        }
  189.     return 0;
  190. }
  191.  
  192. /* Create an array with name values. */
  193. private int
  194. cfont_name_array_create(ref *parray, const char _ds * _ds *str_list,
  195.   int size)
  196. {    ref *aptr = alloc_refs(size, "cfont_name_array_create");
  197.     int i;
  198.     const char _ds * _ds *pstr = str_list;
  199.     if ( aptr == 0 ) return e_VMerror;
  200.     make_tasv(parray, t_array, a_readonly, size, refs, aptr);
  201.     for ( i = 0; i < size; i++, aptr++, pstr++ )
  202.        {    ref nref;
  203.         int code = name_ref((byte *)*pstr, strlen(*pstr), &nref, 0);
  204.         if ( code < 0 ) return code;
  205.         ref_assign_new(aptr, &nref);
  206.        }
  207.     return 0;
  208. }
  209.  
  210. /* Enter a name in a dictionary. */
  211. private int
  212. cfont_dict_put(ref *pdref, const char _ds *nstr, const ref *pvalue)
  213. {    ref nref;
  214.     name_enter(nstr, &nref);
  215.     return dict_put(pdref, &nref, pvalue);
  216. }
  217.